<?php

/**
 * This is the model class for table "articles".
 *
 * The followings are the available columns in table 'articles':
 * @property integer $id
 * @property string $title
 * @property string $post
 * @property integer $edit_time
 * @property integer $order_id
 * @property integer $enabled
 */
class Articles extends ExtActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Articles the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function _tableName()
	{
		return 'articles';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('edit_time, order_id, enabled', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>255),
			array('post', 'safe'),			
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'uploads'=>array(
				self::HAS_MANY,
				'Uploads',
				'id_owner',
				'condition'=>'uploads.owner_type="ARTICLE"',
				'order'=>'uploads.upload_date DESC',
			),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'title' => 'Заголовок',
			'post' => 'Текст',
			'edit_time' => 'Время правки',
			'order_id' => 'Порядок',
			'enabled' => 'Видимый',
		);
	}
	
}